const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    experience_review_src: [
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg"
    ],
    article_review_src: [
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg",
      "../../static/images/index/star.jpg"
    ],
    showInput: false
  },

  // 点击评论按钮，拉起输入框
  handleComment () {
    this.setData({
      showInput: true
    })
  },

  // 提交评论内容
  formSubmit (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    let comment = e.detail.value.comment
    let study_id = 1 // 测试用
    let token = wx.getStorageSync('token')
    app.http({
      config: {
        url: '/api/User/create_study_comment',
        data: {
          token,
          study_id,
          comment
        },
        method: 'POST'
      },
      isAuth: true
    }).then(res => {
      console.log(res, 'commentRes')
    }).catch(err => {
      console.log(err, 'commentErr')
    })
  },

  // 删除评论
  deleteComment (e) {
    let study_comment_id = e.currentTarget.dataset.comment;
    let token = wx.getStorageSync('token')
    app.http({
      config: {
        url: '/api/User/del_study_comment',
        data: {
          token,
          study_comment_id
        },
        method: 'POST'
      },
      isAuth: true
    }).then(res => {
      console.log(res, 'deleteCommentRes')
    }).catch(err => {
      console.log(err, 'deleteCommentErr')
    })
  },

  // 评论输入框失去焦点
  inputBlur () {
    this.setData({
      showInput: false
    })
  },

  // 点赞数
  onFabulous () {
    console.log("点赞数")
  },

  // 分享
  onShare () {
    this.onShareAppMessage()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面转发按钮
      console.log(res.target, res)
    }
    return {
      title: '心得详情',
      path: 'pages/personal_sixitem_Experience_details/personal_sixitem_Experience_details'
    }
  }
})